<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="remark" slot-scope="text">
          <j-ellipsis  :value="text" :length="textMaxLength"></j-ellipsis>
        </template>
        <template slot="fileSlot" slot-scope="text,record">
          <span v-if="text.length ==0" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile2(record)">
            下载
          </a-button>
        </template>
      </a-table>
  </j-modal>
</template>

<script>
  import { httpAction, getAction,postAction ,getFileAccessHttpUrl,downloadFile} from '@/api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  export default {
    name: 'SkInfoSubmitModal',
    mixins:[JeecgListMixin],
    components: {
      JEllipsis
    },
    data () {
      return {
        textMaxLength:10,
        title:'上报详情',
        width:800,
        visible: false,
        disableSubmit: false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          
          {
            title:'幼儿园',
            align:"center",
            dataIndex: 'tenantName'
          },
          {
            title:'上报文件',
            align:"center",
            dataIndex: 'attachmentList',
            scopedSlots: {customRender: "fileSlot"}
          },
          {
            title:'上报时间',
            align:"center",
            dataIndex: 'submitTime'
          },
          {
            title:'上报状态',
            align:"center",
            dataIndex: 'submitStatus',
            customRender:function (t,r,index) {
              return t == 0 ?"未上报":"已上报"
            }
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            scopedSlots: {customRender: "remark"}
          },
        ],
        url: {
          list: "/data/skInfoSubmitDetail/list",
          
        },
      }
    },
    methods: {
      init(record){
        this.queryParam.infoId = record.id;
        this.loadData();
        this.visible = true;
      },
      close () {
        this.visible = false;
      },
      handleOk () {
        this.$refs.realForm.submitForm();
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      downloadFile2(record){
        let fileArr = record.attachmentList;
        fileArr.forEach(item => {
          let url = getFileAccessHttpUrl(item.url)
          downloadFile(url,item.fileName)
        });
      }
    }
  }
</script>